/** @jsx jsx */
import { jsx } from '@emotion/react';
import React, {
    useEffect,
    useLayoutEffect,
    useState,
    useCallback,
    useMemo
} from "react";
import { message, Select, Spin, Checkbox } from "antd";
import { useSelector,connect, useDispatch } from "react-redux";
import axiosMethod from "../../../util/axios";
import CONFIG from "../../../util/config";
import Search from "../../../common/component/search";
import Empty from "../../../common/component/empty";
import { getQueryVariable } from '../../../util/index'
import { LgPaginationA, LgTable, lgAlert, LgButton } from "lancoo-web-ui";
import useGetThem from '../../../hooks/useGetThem';
import styles from './index.module.scss'
import "./index.scss";

function Todo(props) {
    let {
        userInfo,
        currentIdentity,
        noticeAddr:noticeWebAddr,  // !
        skin
    } = useSelector(state => state);
    const { defaultColor, hoverColor, bgColor } = useGetThem(skin)

    const dispatch = useDispatch();
    const [loadVisible, setLoadVisible] = useState(false);

    const [listTotal, setListTotal] = useState(0)

    const typeList = useMemo(() => {
        if (userInfo.UserType === '2' || userInfo.UserType === '3') {
            return [
                {
                    key: 'all',
                    name: '全部',
                    status: ''
                },
                {
                    key: 'noDeal',
                    name: '待处理的',
                    status: 0
                },
                {
                    key: 'alreadyDeal',
                    name: '已处理的',
                    status: 1
                }
            ]
        } else {
            return [
                {
                    key: 'publish',
                    name: '我发布的'
                },
                {
                    key: 'receive',
                    name: '我收到的'
                }
            ]
        }
    }, [userInfo])
    const [currentType, setCurrentType] = useState(typeList[0].key);
    const [keyword, setKeyword] = useState("");

    const [noticeInfo, setNoticeInfo] = useState([]); //我发布的管理员
    const [noticeInfo1, setNoticeInfo1] = useState([]);//我收到的管理员
    const [noticeInfo2, setNoticeInfo2] = useState([]);//家长学生

    const [noticeStatus, setNoticeStatus] = useState('')

    const [noticeAddr, setNoticeAddr] = useState(noticeWebAddr)
    const [currentIndex, setCurrentIndex] = useState(1);
    const [selectList, setSelectList] = useState([]);
    const [chooseList, setChooseList] = useState([])
    const selectStatus = useMemo(() => {
        let sign = 0;
        if (selectList.length > 0 && selectList.length < 10) {
            sign = 1;
        } else if (selectList.length === 10) {
            sign = 2;
        }
        // console.log(sign, selectList)
        return sign;
    }, [selectList]);


    const changeType = useCallback((data) => {
        setCurrentType(data.key);
        setCurrentIndex(1)
    }, []);

    const getNoticeAddr = useCallback(() => {
        window.getWebAddr("220", function (data) {
            setNoticeAddr(data);
        })
    }, []);


    const getList = useCallback((pageIndex = currentIndex,isPublish=false) => {
        setLoadVisible(true);
        // 管理员和教师对班级通知进行数据获取
        if (userInfo.UserType !== '2' && userInfo.UserType !== '3') {
            let noticeUrl = '', body = {}
            if (currentType === 'publish' || isPublish) {
                noticeUrl = `/api/notice/list/creator/page/${pageIndex}/10`
                body = {
                    userId: userInfo.UserID,
                    eduId: userInfo.SchoolID,
                    keyword: keyword,
                    noticeNature: 3,
                }
            } else {
                noticeUrl = `api/notice/list/receiver/page/${pageIndex}/10`
                body = {
                    userId: userInfo.UserID,
                    schoolId: userInfo.SchoolID,
                    Token: sessionStorage.getItem("token"),
                    keyword: keyword,
                    noticeNature: 3,
                }
            }

            axiosMethod({
                type: "get",
                url: noticeAddr + noticeUrl,
                body,
                isBackAll: true,
                callback: function (res) {
                    if (currentType === 'publish') {
                        res.data.forEach(function (item, index) {
                            item.option = [item.noticeId, item.status]
                            item.key = item.taskReleaseId || item.noticeId
                            item.title = {
                                'title': item.title,
                                'hasFile': item.haveAttachment,
                                'noticeId': item.noticeId,
                                "taskReleaseId": item.taskReleaseId
                            }
                            item.readState = item.readNum && item.unReadNum ? (item.readNum + '/' + item.unReadNum) : '--'
                        })
                        setNoticeInfo(res.data);
                        setListTotal(res.total)
                    } else {  //教师任课老师 我收到的
                        res.data.notices.forEach(function (item, index) {
                            item.key = item.taskReleaseId || item.noticeId
                        })
                        setNoticeInfo1(res.data.notices)
                        setListTotal(res.data.total)
                    }

                    typeof window.recordReadTime === "function" &&
                        window.recordReadTime("notice");
                    setLoadVisible(false);
                }
            });
        } else { //学生和家长获取班级通知 先获取待办
            let classNoticeArr = [], noticeTotal = 0, status = '', readStatus = ''

            switch (currentType) {
                case 'all':
                    break;
                case 'noDeal':
                    status = '0';
                    readStatus = 0;
                    break;
                case 'alreadyDeal':
                    status = '3';
                    readStatus = 1;
                    break;
                default:
                    break;
            }


            axiosMethod({
                url: '/api/todo/list/getPageList',
                body: {
                    pageIndex: 1,
                    pageSize: 9999,
                    userId: userInfo.UserID,
                    userType: userInfo.UserType,
                    schoolId: userInfo.SchoolID,
                    noticeType: '1',
                    keyWord: keyword,
                    status
                },
                isBackAll: true,
                callback: function (result) {
                    // console.log('todo', result)
                    let todoNum = Number(result.total)
                    let oldTodoInfo = []
                    noticeTotal += todoNum
                    oldTodoInfo = result.data
                    let newTodoInfo = []
                    if (oldTodoInfo.length > 0) {
                        oldTodoInfo.forEach(function (item) {
                            if (item.receiverType == 0 || item.receiverType == 1 || item.receiverType == 4 || item.receiverType == 5) {
                                newTodoInfo.push(item)
                            }
                        })
                    }
                    classNoticeArr = newTodoInfo

                    if (!noticeAddr) {
                        getNoticeAddr()
                        return
                    }

                    axiosMethod({
                        type: 'get',
                        url: noticeAddr + "/api/notice/list/receiver/page/1/9999",
                        body: {
                            userId: userInfo.UserID,
                            schoolId: userInfo.SchoolID,
                            keyword,
                            noticeNature: 3,
                            readStatus,
                        },
                        isBackAll: true,
                        callback: function (data) {
                            if (data.code === '200') {
                                let isInit = true
                                // if (classNoticeArr.some(function (item) {
                                //     return item.noticeId
                                // })) {
                                //     isInit = false
                                // }
                                if (isInit) {
                                    classNoticeArr = classNoticeArr.concat(data.data.notices);
                                    noticeTotal += Number(data.data.total);
                                }

                                classNoticeArr.forEach(function (item, index) {
                                    item.key = item?.msgId || item?.taskReleaseId || item?.noticeId || index
                                    item.dueTime = Date.parse(item.msgPushTime || item.taskReleaseTime || item.releaseTime);
                                })

                                classNoticeArr.sort(function (a, b) {
                                    return b.dueTime - a.dueTime;
                                });


                                if (pageIndex > 1 && classNoticeArr.length > 0) {
                                    setNoticeInfo2(classNoticeArr.slice((pageIndex - 1) * 10, pageIndex * 10))
                                } else {
                                    setNoticeInfo2(classNoticeArr.slice(0, 10))
                                }

                                // console.log(classNoticeArr, noticeTotal, pageIndex)

                                setListTotal(classNoticeArr.length)
                                setLoadVisible(false)
                            }
                        }
                    })
                }
            })

        }
    }, [noticeAddr, keyword, currentIndex, userInfo, currentType, getNoticeAddr, noticeStatus]);

    const noticeClick = useCallback((data, type) => {
        if (data.noticeId) {
            if (type !== 'publish') {
                setRead(data, 2)
                window.open(noticeAddr + `web/html/announcement/index.html?lg_tk=${sessionStorage.getItem("token")}&lg_ic=${currentIdentity.identityCode}&noticeId=${data.noticeId}&taskReleaseId=${data.taskReleaseId ? data.taskReleaseId : ""}#/noticeDetail`)
            } else {
                window.open(noticeAddr + `web/html/announcement/index.html?lg_tk=${sessionStorage.getItem("token")}&lg_ic=${currentIdentity.identityCode}&noticeId=${data.noticeId}&taskReleaseId=${data.taskReleaseId ? data.taskReleaseId : ""}&noticeType=publish#/noticeDetail`)
            }
        } else {
            todoClick(data)
        }
    }, [noticeAddr, currentIndex, currentIdentity, setRead, todoClick, noticeStatus]);

    const todoClick = useCallback((data) => {
        if (!data.pcLink) {
            return
        }

        if (data.pcLinkType === '1') {
            window.getWebAddr(data.sysId, function (webAddr) {
                let url = data.pcLink
                    .replace("[token]", sessionStorage.getItem("token"))
                    .replace("[IdentityCode]", currentIdentity.identityCode);
                window.open(webAddr + url);
            })
        } else if (data.pcLink === '3') {
            window.open(data.pcLinkType.replace("[token]", sessionStorage.getItem("token")).replace("[IdentityCode]", currentIdentity.identityCode), '_blank')
        }
    }, [currentIdentity]);

    // 我发起的进行催读status=1&type=urgeRead 撤回status=1&type=delete 删除status=-1&type=delete
    const setUrgeRead = useCallback((value, type, e, notice) => {
        let url = '', status = value[1], requestType = 'post', noticeId = value[0]

        if (type === 'urgeRead') {
            if (status === '1') { //催读
                url = noticeAddr + `/api/notice/manage/urge/read?noticeId=${noticeId}`
            } else {  //编辑
                url = `${noticeAddr}/web/html/announcement/index.html?lg_tk=${getQueryVariable('lg_tk')}&lg_ic=${getQueryVariable('lg_ic')}&noticeId=${noticeId}#/createNormalNotice`
                let publishInfo = {
                    visible: true,
                    title: notice?.noticeType == '1' ? '编辑紧急通知' : '编辑通知公告',
                    showUrgent: false,
                    url,
                }
                dispatch({
                    type: 'SET_NOTICEPUBLISHINFO',
                    data: publishInfo
                })
                // window.open(noticeAddr + "/web/html/announcement/index.html?lg_tk=" + sessionStorage.getItem('token') + "&lg_ic=" + currentIdentity.identityCode, '_blank')
                return
            }
        } else if (type === 'delete') {
            if (status === '-1') { // 删除
                url = noticeAddr + `/api/notice/manage/del?noticeId=${noticeId}`
                requestType = 'delete'
                let alert = lgAlert.show({
                    duration: 0,
                    content: '确定要删除该通知吗？',
                    isShowCloseBtn: true,
                    tipType: 'question',
                    tipSize: 'small',
                    tipMouldType: 'A',
                    confirmText: "确认",
                    closeText: "再想想",
                    onConfirm: () => {
                        axiosMethod({
                            type: requestType,
                            url,
                            body: {
                                noticeId: value[0]
                            },
                            isBackAll: true,
                            callback: function (result) {
                                if (result.code === '200') {
                                    message.success('删除成功')
                                    getList()
                                }
                            }
                        })
                        lgAlert.close(alert.index)
                        return
                    }
                });
            } else if (status === '1') {  //撤回
                url = noticeAddr + `/api/notice/manage/callback`
                requestType = 'PUT'
            }
        }

        if (type === 'delete' && status === '-1') {
            return
        }

        axiosMethod({
            type: requestType,
            url,
            body: {
                noticeId: value[0]
            },
            isBackAll: true,
            callback: function (result) {
                if (result.code === '200') {
                    if (type === 'urgeRead') {
                        message.success('催读成功')
                    } else {
                        message.success('撤回成功')
                        getList()
                    }
                }
            }
        })
    }, [noticeAddr, getList, currentIdentity])

    // 列表列名称
    const columns = useMemo(() => {
        const option = { '-1': '编辑', '1': '催读' }
        const option2 = { '-1': '删除', '1': '撤回' }
        const publishStatus = {
            '0': '已过期',
            '1': '已发布',
            '-1': '未发布'
        }
        if (userInfo.UserType !== '2' && userInfo.UserType !== '3') {
            if (currentType === 'publish') {
                return [
                    {
                        dataIndex: "status",
                        key: "status",
                        align: "center",
                        render: (value, record, index) => {
                            return <span className={styles["publish-status" + value]}>{publishStatus[value]}</span>;
                        },
                    },
                    {
                        title: '标题',
                        dataIndex: 'title',
                        key: "title",
                        render: (value) => {
                            return <span
                                title={value.title}
                                onClick={() => { noticeClick(value, 'publish') }}
                                className={styles["publish-title"]}
                            >
                                <span>{value.title}</span>
                                <span style={{ display: `${value.hasFile == 0 ? 'none' : ''}` }}></span>
                            </span>;
                        },
                    },
                    {
                        title: '发布时间',
                        dataIndex: 'releaseTime',
                        key: "releaseTime",
                        align: "center",
                        render: (value) => {
                            return <span className={styles["publish-date"]}>{value || '--'}</span>;
                        },
                    },
                    {
                        title: '已读/未读',
                        dataIndex: 'readState',
                        key: "readState",
                        render: (value) => {
                            return <span className={styles["read-status"]}>{value}</span>;
                        },
                    },
                    {
                        title: '操作',
                        dataIndex: 'option',
                        key: "option",
                        render: (value, record) => {
                            return <span className={styles["publish-option"]}>
                                {
                                    value[1] ?
                                        <>
                                            <span
                                                onClick={(e) => { setUrgeRead(value, 'urgeRead', e, record) }}
                                                className={styles['urge-read']}
                                            >
                                                {option[value[1]]}
                                            </span>
                                            <i></i>
                                        </> : ''
                                }
                                <span
                                    onClick={(e) => { setUrgeRead(value, 'delete', e, record) }}
                                    className={styles["del"]}
                                >
                                    {option2[value[1]]}
                                </span>
                            </span >;
                        },
                    },
                ]
            } else if (currentType === 'receive') {
                return [
                    {
                        dataIndex: "serial",
                        key: "serial",
                        align: "center",
                        render: (value, record, index) => {
                            return (
                                <div
                                    style={{ display: 'flex', paddingLeft: '10px' }} key={'checkbox' + index}
                                >
                                    <Checkbox
                                        checked={record.check}
                                        onClick={(e) => selectNotice(record, index, e, 'receive')}
                                    />
                                </div>
                            )

                        }
                    },
                    {
                        title: '标题',
                        dataIndex: 'title',
                        key: "title",
                        render: (value, record) => {
                            return <span
                                className={styles["admin-receive-title"]}
                            >
                                {
                                    record.readStatus == 0 ?
                                        <span className={styles['unRead-point']}></span> :
                                        <span className={styles['unRead-point-empty']}></span>
                                }
                                <span
                                    className={styles['title']}
                                    title={value}
                                    onClick={() => { noticeClick(record) }}
                                    style={{
                                        color: `${record.readStatus == 0 ? '#333333' : '#999999'}`,
                                        fontWeight: `${record.readStatus == 0 ? '' : 'normal'}`,
                                        cursor: 'pointer'
                                    }}
                                >{value}</span>
                            </span>;
                        },
                    },
                    {
                        title: '发布人',
                        dataIndex: 'userName',
                        key: "userName",
                        render: (value, record) => {
                            return <span title={value} style={{ color: `${record.status == 0 || record.readStatus == 0 ? '#333333' : '#999999'}` }} title={value} className={styles["publish-name"]}>{value}</span>;
                        },
                    },
                    {
                        title: '发布时间',
                        dataIndex: 'releaseTime',
                        key: "releaseTime",
                        align: 'center',
                        render: (value) => {
                            return <span className={styles["publish-date"]}>{value}</span>;
                        },
                    },

                    {
                        title: '操作',
                        dataIndex: 'operation',
                        key: "operation",
                        render: (value, record) => {
                            const { readStatus } = record
                            if (readStatus === '0') {
                                return (
                                    <div className={styles["receive-option"]}>
                                        <LgButton
                                            shapeType="text"
                                            textUnderline={false}
                                            size="small"
                                            type="info"
                                            onClick={(e) => { setRead(record, 1, e) }}
                                        >
                                            设为已读
                                        </LgButton>
                                        <div className={styles["divider"]}></div>
                                        <LgButton
                                            className={styles["delete"]}
                                            shapeType="text"
                                            textUnderline={false}
                                            type='fail'
                                            size="small"
                                            onClick={() => { setDelete(record) }}
                                        >
                                            删除
                                        </LgButton>
                                    </div>
                                )
                            } else {
                                return <LgButton
                                    className={styles["delete"]}
                                    shapeType="text"
                                    textUnderline={false}
                                    size="small"
                                    type='fail'
                                    onClick={() => { setDelete(record) }}
                                >

                                    删除
                                </LgButton>
                            }
                        },
                    },
                ]
            }
        } else {
            return [
                {
                    title: '标题',
                    dataIndex: 'title',
                    key: "title",
                    render: (value, record) => {
                        return <span className={styles["student-notice-title"]}>
                            {
                                record.status == 0 || record.readStatus == 0 ?
                                    <i className={styles["unRead-point"]}></i> : ''
                            }
                            {
                                record.msgSourceName ?
                                    <span className={styles['todo-source' + record.status]}>{record.msgSourceName}</span> : ""
                            }
                            <span
                                title={record.title || record.msgPushContent}
                                style={{
                                    color: `${record.status == 0 || record.readStatus == 0 ? '#333333' : '#999999'}`,
                                    fontWeight: `${record.readStatus == 0 ? '' : 'normal'}`,
                                    cursor: "pointer"
                                }}
                                className={styles['title']}
                                onClick={() => noticeClick(record)}
                            >{record.title || record.msgPushContent}
                            </span>
                        </span>;
                    },
                },
                {
                    title: '发布人',
                    dataIndex: 'userName',
                    key: "userName",
                    render: (value, record) => {
                        return <span title={value} style={{ color: `${record.status == 0 || record.readStatus == 0 ? '#333333' : '#999999'}` }} className={styles["publish-name"]}>{value}</span>;
                    },
                },
                {
                    title: '发布时间',
                    dataIndex: 'releaseTime',
                    key: "releaseTime",
                    align: 'center',
                    render: (value, record) => {
                        return <span className={styles["publish-date"]}>{(record?.taskReleaseTime || record.releaseTime || record.msgPushTime).substring(0, 16)}</span>;
                    },
                },

                {
                    title: '操作',
                    dataIndex: 'operation',
                    key: "operation",
                    render: (value, record) => {
                        const { readStatus } = record
                        if (readStatus) {
                            if (readStatus === '0') {
                                return (
                                    <div className={styles["receive-option"]}>
                                        <div>
                                            <LgButton
                                                shapeType="text"
                                                textUnderline={false}
                                                size="small"
                                                type="info"
                                                onClick={(e) => { setRead(record, 1, e) }}
                                            >
                                                设为已读
                                            </LgButton>
                                        </div>
                                        <div className={styles["divider"]}></div>
                                        <LgButton
                                            className={styles["delete"]}
                                            shapeType="text"
                                            textUnderline={false}
                                            type='fail'
                                            size="small"
                                            onClick={(e) => { setDelete(record, e) }}
                                        >
                                            删除
                                        </LgButton>
                                    </div>
                                )
                            } else {
                                return <LgButton
                                    className={styles["delete"]}
                                    shapeType="text"
                                    textUnderline={false}
                                    size="small"
                                    type="fail"
                                    onClick={(e) => { setDelete(record, e) }}
                                >
                                    删除
                                </LgButton>
                            }
                        } else {
                            return <LgButton
                                className={styles["delete"]}
                                shapeType="text"
                                textUnderline={false}
                                size="small"
                                type="info"
                                onClick={() => { todoClick(record) }}
                            >
                                详情
                            </LgButton>
                        }
                    },
                },
            ]
        }
    }, [userInfo, currentType, selectNotice, selectList, setRead, setDelete, setUrgeRead, todoClick, noticeClick])

    const searchMethod = useCallback((value) => {  //搜索函数
        setKeyword(value);
        // if (currentIndex === 1) {
        //     getList();
        // } else {
        //     setCurrentIndex(1);
        // }
    }, [currentIndex, getList]);


    const selectNotice = useCallback((data, index, e, type) => {
        // console.log(data, e)
        e && e.stopPropagation();
        let list = JSON.parse(JSON.stringify(selectList)), target = "";
        list.forEach((item, index) => {
            if (item.noticeId === data.noticeId) {
                target = index;
            }
        })
        if (typeof target === "number") {
            list.splice(target, 1);
        } else {
            list.push(data);
        }
        // console.log(selectList, data, list)
        setSelectList(list);
    }, [selectList]);

    const changeSelectSign = useCallback((e) => {
        // console.log(e.target.checked)
        let list = [];
        if (e.target.checked) {
            list = noticeInfo1
        }
        setSelectList(list);
    }, [noticeInfo1]);

    const setRead = useCallback((data, type, e) => {  //设置已读
        e && e.stopPropagation();
        let ids = [], taskIds = [];
        if (data) {
            ids.push(data.noticeId);
        } else {
            selectList.forEach(item => {
                if (item.timeType == 1) {
                    taskIds.push(item.taskReleaseId);
                } else {
                    ids.push(item.noticeId);
                }
            });
            if (!ids.length && !taskIds.length) {
                message.warn("至少选择一个通知");
                return;
            }
        }
        axiosMethod({
            type: "put",
            url: noticeAddr + "/api/notice/receiver/batch/read",
            body: {
                userId: userInfo.UserID,
                noticeIds: ids,
                taskReleaseIds: taskIds
            },
            header: {
                Authorization: `${sessionStorage.getItem("token")}`
            },
            callback: function (res) {
                if (type === 1) {
                    message.success("设置成功");
                }
                typeof window.getReadInfo === "function" && window.getReadInfo();
                if (data) {

                } else {
                    setSelectList([]);
                }
                getList();
                window.getNewRemindCount && typeof window.getNewRemindCount === 'function' && window.getNewRemindCount()

            }
        });
    }, [noticeAddr, selectList, userInfo, getList, noticeStatus]);

    const setDelete = useCallback((data, e) => {   //设置删除
        e && e.stopPropagation();
        let ids = [], taskIds = [];
        if (!data) {
            selectList.forEach(item => {
                if (item.timeType == 1) {
                    taskIds.push(item.taskReleaseId);
                } else {
                    ids.push(item.noticeId);
                }
            });
            if (!ids.length && !taskIds.length) {
                message.warn("至少选择一个通知");
                return;
            }
        }
        let noticeTitle = ''
        if (data || selectList.length === 1) {
            noticeTitle = '确定要删除该通知吗？'
        } else {
            noticeTitle = `确定要批量删除这${selectList.length}条通知吗`
        }
        dispatch({
            type: "SET_ALERTINFO",
            data: {
                visible: true,
                title: noticeTitle,
                onCancel: function () {
                    dispatch({
                        type: "SET_ALERTINFO",
                        data: {}
                    })
                },
                onOk: function () {
                    let ids = [], taskIds = [], params = {};
                    if (data) {
                        params = {
                            userId: userInfo.UserID,
                            noticeIds: [data.noticeId]
                        };
                        if (data.timeType == 1) {
                            params = {
                                userId: userInfo.UserID,
                                taskReleaseIds: [data.taskReleaseId]
                            };
                        }
                    } else {
                        selectList.forEach((item) => {
                            if (item.timeType == 1) {
                                taskIds.push(item.taskReleaseId);
                            } else {
                                ids.push(item.noticeId);
                            }
                        })
                        params = {
                            userId: userInfo.UserID,
                            noticeIds: ids,
                            taskReleaseIds: taskIds
                        };
                    }
                    axiosMethod({
                        type: "delete",
                        url: noticeAddr + "/api/notice/receiver/batch/del",
                        body: params,
                        header: {
                            Authorization: `${sessionStorage.getItem("token")}`
                        },
                        callback: function (res) {
                            message.success("删除成功");
                            if (data) {
                            } else {
                                setSelectList([]);
                            }
                            dispatch({
                                type: "SET_ALERTINFO",
                                data: {}
                            })
                            setCurrentIndex(1)
                            getList(1);
                        }
                    });
                }
            }
        })

    }, [noticeAddr, selectList, userInfo, dispatch, getList]);

    const goNotice = useCallback((type, noticeKind = 3) => {
        let url = ''
        url = `${noticeAddr}web/html/announcement/index.html?lg_tk=${getQueryVariable('lg_tk')}&lg_ic=${getQueryVariable('lg_ic')}&noticeKind=3#/createNormalNotice`
        let publishInfo = {
            visible: true,
            title: type === 'urgent' ? '发布紧急通知' : noticeKind == 1 ? '发布学校通知' : '发布班级通知',
            currentKind: noticeKind,
            showUrgent: type === 'urgent' ? true : false,
            url,
        }
        dispatch({
            type: 'SET_NOTICEPUBLISHINFO',
            data: publishInfo
        })
        // window.open(noticeAddr + `web/html/announcement/index.html?lg_tk=${sessionStorage.getItem("token")}&lg_ic=${currentIdentity.identityCode}&${type === "urgent" ? "showUrgent=true" : "showPublish=true"}&noticeKind=${noticeKind}`)
    }, [noticeAddr, currentIdentity]);

    useEffect(() => {
        let info = JSON.parse(JSON.stringify(noticeInfo1));
        Array.isArray(info) &&
            info.forEach((item) => {
                let sign = false;
                selectList.forEach((child, index) => {
                    if (item.noticeId === child.noticeId) {
                        sign = true
                    }
                })
                item.check = sign;
            })
        setNoticeInfo1(info);
    }, [selectList])

    useEffect(() => {
        setSelectList([]);
        getList();
    }, [getList, currentIndex, noticeAddr, keyword]);

    useLayoutEffect(() => {
        window._getSchoolNotice = getList
    }, [getList, currentIndex,currentType, noticeAddr, keyword])

    return (
        <div className='main_notice'>
            <Spin spinning={loadVisible} tip="加载中...">
                <div className="notice_option">
                    {
                        typeList.map((item, index) => (
                            <span
                                className={`option_one`}
                                css={{
                                    color: item.key === currentType ? defaultColor : '',
                                    borderColor: `${defaultColor}!important`,
                                    backgroundColor: item.key === currentType ? bgColor : '',
                                    '&:hover': {
                                        color: hoverColor,
                                    }
                                }}
                                onClick={() => changeType(item)}
                                key={index}>{item.name}</span>
                        ))
                    }
                    <span className="list_info">共<span>{listTotal}</span>条</span>
                    {
                        userInfo.UserType == 0 || userInfo.UserType == 1 || userInfo.UserType == 11 ?
                            <span className="notice_btn" onClick={() => goNotice("", 3)}><i></i>发布班级通知</span> : ''
                    }
                    <Search className="option_search" searchMethod={searchMethod} placeholder="搜索通知发布者或通知内容..." />
                </div>
                <div className="notice_list">
                    {

                        currentType === 'publish' && noticeInfo.length > 0 ?
                            <div className="publish_Tab">
                                <LgTable columns={columns} data={noticeInfo} onClick={() => { console.log('111111') }} />
                            </div> :
                            currentType === 'receive' && noticeInfo1.length > 0 ?
                                <div className="receive_Tab">
                                    <LgTable columns={columns} data={noticeInfo1} />
                                </div>
                                :
                                (currentType === 'all' || currentType === 'noDeal' || currentType === 'alreadyDeal') && noticeInfo2.length > 0 ?
                                    <div className="stu_receive_Tab">
                                        <LgTable columns={columns} data={noticeInfo2} />
                                    </div> :
                                    <Empty style={{ marginTop: 160 }} />

                    }
                    {
                        // Array.isArray(noticeInfo.notices) &&
                        //     noticeInfo.length > 0 ?
                        //     noticeInfo.map((item, index) => (
                        //         <div className="notice_one" key={index} onClick={() => noticeClick(item)}>
                        //             <Checkbox checked={item.check} onClick={(e) => selectNotice(item, index, e)} />
                        //             {/* <i className="checklogo"></i> */}
                        //             <div className="one_info">
                        //                 <h4 className={`info_title ${item.readStatus === "1" ? "read" : ""}`} title={item.title}>
                        //                     {
                        //                         item.noticeType === "1" ?
                        //                             <span style={{ color: "#ff0000" }}>[紧急]</span> :
                        //                             ""
                        //                     }
                        //                     {
                        //                         item.noticeClass == 2 ?
                        //                             <span style={{ color: "#ff6600" }}>[教育局]</span> :
                        //                             ""
                        //                     }
                        //                     {item.title}
                        //                 </h4>
                        //                 <p className="info_detail">
                        //                     {/* 教务通知 */}
                        //                     {/* <span className="detail_line">|</span> */}
                        //                     {decodeURIComponent(item.userName)}
                        //                     <span className="detail_line"></span>
                        //                     {item.startTime && item.startTime.substr(0, 16)}
                        //                 </p>
                        //             </div>
                        //             <div className="one_option">
                        //                 {
                        //                     item.readStatus === "1" ?
                        //                         "" :
                        //                         <>
                        //                             <span className="blue_text" onClick={(e) => setRead(item, e)}>设为已读</span>
                        //                             <span className="slice_line"></span>
                        //                         </>
                        //                 }
                        //                 <span className="red_text" onClick={(e) => setDelete(item, e)}>删除</span>
                        //             </div>
                        //         </div>
                        //     )) :

                    }
                </div>
                {
                    Number(listTotal) > 0 ?
                        <div className="class_notice_footer">
                            {
                                currentType === 'publish' || currentType === 'all' || currentType === 'noDeal' || currentType === 'alreadyDeal' ?
                                    '' :
                                    <div className="left_option" style={{}}>
                                        <Checkbox
                                            checked={selectStatus === 2 || selectStatus === 1 ? true : false}
                                            onChange={changeSelectSign}
                                            indeterminate={selectStatus === 1 ? true : false}>全选</Checkbox>
                                        <span className="blue_btn" onClick={(e) => setRead("", 1, e)}>批量设置为已读</span>
                                        <span className="red_btn" onClick={(e) => setDelete("", e)}>批量删除</span>
                                    </div>
                            }

                            <div className="lg-skin-s2 pageOption" style={{ display: `${listTotal > 10 ? 'block' : 'none'}` }}>
                                <LgPaginationA
                                    total={Math.ceil(listTotal / 10)}
                                    size="normal"
                                    currentPage={currentIndex}
                                    onChangePage={(pageIndex) => {
                                        setCurrentIndex(pageIndex);
                                    }}
                                ></LgPaginationA>
                            </div>

                        </div> : ""
                }
            </Spin>

        </div>
    )
}
// const mapProps = (state) => {
//     return {
//         userInfo: state.userInfo,
//         sysAddrInfo: state.sysAddrInfo,
//         currentIdentity: state.currentIdentity,
//         sysInfo: state.sysInfo,
//         alertInfo: state.alertInfo,
//         noticeWebAddr: state.noticeAddr
//     }
// }
// export default connect(mapProps)(Todo);
export default Todo;